//
// Created by vcq on 21/2/10.
//
#pragma once
#include "dbng.hpp"
#include "utils_dao.hpp"
#include "__base_mode__.hpp"
#include <string>
using namespace nlohmann;
using namespace std;
using Dao = dao_t<dbng<mysql>>;
struct plan {
    int id;
    string name;
    string note;
    string _grade_id;
    string _profession_id;
};
REFLECTION(plan, id, name,_grade_id,_profession_id,note)

json mgetPlan(basic_string_view<char> id){
    string sql="select * from plan where 1=1 ";
    if (!id.empty()) {
        sql += "and id =";
        sql += id;
    }
    Dao dao;
    auto v = dao.query<plan>(sql);
    nlohmann::json article_list,ret,item;
    for (auto& o : v) {
        item["id"]=o.id;
        item["name"]=o.name;
        item["note"]=o.note;
        item["_grade_id"]=o._grade_id;
        item["_profession_id"]=o._profession_id;
        article_list.push_back(item);
    }
    ret["code"]=0;
    ret["count"]=article_list.size();
    ret["data"]=article_list;
    return ret;
}
void add_plan(const struct plan& baseplan){
    Dao dao;
    dao.update_object(baseplan);
}
void MDeletePlan(basic_string_view<char> id){
    MDeleteAll("plan",id);
}